{extend name="public:base" /}
{block name="content"}	
<div class="page-header">
	<h1>
		{$breadcrumb1}
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			{$breadcrumb2}
		</small>
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			{$crumbs}
		</small>			

	</h1>
</div>
	<div class="row">
	<div class="col-xs-12">	
		<div class="panel-body">
        <form  method="post" enctype="multipart/form-data" id="form-goods" class="form-horizontal">

          <ul class="nav nav-tabs">
          	
          	<li class="active"><a href="#tab-data" data-toggle="tab">{$crumbs}</a></li>
           
          </ul>
          <div class="tab-content">
          		
	       	<!-- 关联 START -->
	          	<div class="tab-pane active" id="tab-data">	          		
	         
	          		<div class="table-responsive">
	          			
	          			<table id="mobile_images" class="table table-striped table-bordered table-hover">
		                  <thead>
		                    <tr>
		                      <td class="text-left">详情图片</td>
		                      <td class="text-left">图片描述</td>
		                      <td class="text-right">选项排序</td>
		                      <td></td>
		                    </tr>
		                  </thead>
		                	 <tbody>
			                     <?php $mobile_image_row = 0; ?>
			                     <?php if(isset($mobile_images)){ ?>
				                    <?php foreach ($mobile_images as $mobile_image) { ?>
					                    <tr id="mobile-image-row<?php echo $mobile_image_row; ?>">
					                      <td class="text-left"><a href="#" id="mobile-thumb-image<?php echo $mobile_image_row; ?>" data-toggle="image" class="img-thumbnail"><img src="/<?php echo resize($mobile_image['image'],100,100); ?>" /></a><input type="hidden" name="goods_mobile_description_image[<?php echo $mobile_image_row; ?>][image]" value="<?php echo $mobile_image['image']; ?>" id="mobile-input-image<?php echo $mobile_image_row; ?>" /></td>
					                      <td class="text-right"><input type="text" name="goods_mobile_description_image[<?php echo $mobile_image_row; ?>][description]" value="<?php echo $mobile_image['description']; ?>" class="form-control" /></td>
					                      
					                      <td class="text-right"><input type="text" name="goods_mobile_description_image[<?php echo $mobile_image_row; ?>][sort_order]" value="<?php echo $mobile_image['sort_order']; ?>" size="1" class="form-control" /></td>
					                      <td class="text-left">
			                     			<input type="hidden" name="table" value="goods_mobile_description_image" />
							
											<input type="hidden" name="goods_id" value="{$Request.param.id}" />
											
											<input type="hidden" name="pk_id" value="mdi_id" />
											
											<input type="hidden" name="id" value="<?php echo $mobile_image['mdi_id']; ?>" />
											
											<input type="hidden" name="key" value="<?php echo $mobile_image_row; ?>" />
					                      	
					                      	<button type="button" bid="mobile-image-row<?php echo $mobile_image_row; ?>" class="btn save btn-primary"><i class="fa fa-floppy-o"></i></button>
					                      	<button type="button" bid="mobile-image-row<?php echo $mobile_image_row; ?>" class="btn del btn-danger"><i class="fa fa-trash"></i></button></td>
			                    		</tr>
				                    <?php $mobile_image_row++; ?>
				                    <?php } ?>
				                 <?php } ?>
			                  </tbody>
					          </table>
		               		 <div><a  onclick="add_mobile_image();" class="add_image btn btn-primary ">添加图片</a></div>
	          			
          		
            
            
              				</div>          		
          	
    						</div>
          </div>
        </form>
	</div>
	</div>
</div>
{/block}
{block name="javascript"}
<script>	

var mobile_image_row = '<?php echo $mobile_image_row; ?>';

	function add_mobile_image() {
		html  = '<tr id="mobile-image-row' + mobile_image_row + '">';
		html += '  <td class="text-left"><a href="#" id="mobile-thumb-image' + mobile_image_row + '"data-toggle="image" class="img-thumbnail"><img src="__PUBLIC__/image/no_image_100x100.jpg" /><input type="hidden" name="goods_mobile_description_image[' + mobile_image_row + '][image]" value="" id="mobile-input-image' + mobile_image_row + '" /></td>';
		html += '<td class="text-right"><input type="text" name="goods_mobile_description_image['+mobile_image_row+'][description]" value="" class="form-control" /></td>';
		html += '  <td class="text-right"><input type="text" name="goods_mobile_description_image[' + mobile_image_row + '][sort_order]" value="'+mobile_image_row+'"  size="1" class="form-control" /></td>';
		
		html += '  <td class="text-left">';
		
		html += '<input type="hidden" name="table" value="goods_mobile_description_image" />';
  		
  		html += '<input type="hidden" name="goods_id" value="{$Request.param.id}" />';
  		
  		html += '<input type="hidden" name="pk_id" value="mdi_id" />';
  							
		html += '<input type="hidden" name="id" value="" />';
		
		html += '<input type="hidden" name="key" value="' + mobile_image_row + '" />';
		
		html += '<button type="button"  bid="mobile-image-row' + mobile_image_row + '"  class="btn save btn-primary"><i class="fa fa-floppy-o"></i></button>';
		html += '<button type="button"  bid="mobile-image-row' + mobile_image_row + '"  class="btn del btn-danger"><i class="fa fa-trash"></i></button>';
		html += '</td>';
		
		html += '</tr>';
		html += '</tr>';
		
		$('#mobile_images tbody').append(html);
		
		mobile_image_row++;
	}



	
$('.save').live('click', function() {
	
	var id='#'+$(this).attr('bid');	
	
	$.post(
		"{:url('Goods/ajax_eidt')}",
		$(id+' input[type=\'text\'],'+id+' input[type=\'hidden\']'),
		function(d){
			
			if(d.success){
				
				alert(d.success);
				
				if(d.id){
					$(id).find('input[name=\'id\']').val(d.id);
				}
				
			}else if(d.error){
				alert(d.error);
			}
		}
	);

});	
$('.del').live('click', function() {
	var f=confirm('确认要删除吗？');
	
	if(f==false){
		return false;
	}
	
	var id='#'+$(this).attr('bid');	
	
	$.post(
		"{:url('Goods/ajax_del')}",
		$(id+' input[type=\'hidden\']'),
		function(d){
			if(d.success){				
				alert(d.success);
				$(id).remove();
			}else if(d.error){
				alert(d.error);
				$(id).remove();
			}
		}
	);

});	
</script>
{/block}